import java.util.Stack;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 06 - 01
 * Time: 19:58
 */
class MyQueue {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if(empty()) {
            return -1;
        }
        if(!stack1.isEmpty() && stack2.isEmpty()) {
            int num = stack1.size();//stack1.size()不能写在for循环i<stack1.size()中，因为stack1每弹出一个元素，stack1.size()会减一，即stack1.size()不固定
            for(int i = 0; i < num; i++) {
                int x = stack1.pop();
                stack2.push(x);
            }
            return stack2.pop();
        }
        return stack2.pop();
    }

    public int peek() {
        if(empty()) {
            return -1;
        }
        if(!stack1.isEmpty() && stack2.isEmpty()) {
            int num = stack1.size();
            for(int i = 0; i < num; i++) {
                int x = stack1.pop();
                stack2.push(x);
            }
            return stack2.peek();
        }
        return stack2.peek();
    }

    public boolean empty() {
        if(stack1.isEmpty() && stack2.isEmpty()) {
            return true;
        }else {
            return false;
        }
    }
}



class MyQueue1 {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MyQueue1() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if(empty()) {
            return -1;
        }
        if(stack2.isEmpty()) {
            while(!stack1.isEmpty()) {
                int x = stack1.pop();
                stack2.push(x);
            }
            return stack2.pop();
        }
        return stack2.pop();
    }

    public int peek() {
        if(empty()) {
            return -1;
        }
        if(stack2.isEmpty()) {
            while(!stack1.isEmpty()) {
                int x = stack1.pop();
                stack2.push(x);
            }
            return stack2.peek();
        }
        return stack2.peek();
    }

    public boolean empty() {
        if(stack1.isEmpty() && stack2.isEmpty()) {
            return true;
        }else {
            return false;
        }
    }
}
